# Contributor: MehdiChinoune <mehdi.chinoune@hotmail.com>

_realname=immer
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.1
pkgrel=1
pkgdesc="Postmodern immutable and persistent data structures for C++ — value semantics at scale (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://sinusoid.es/immer'
license=('spdx:BSL-1.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/arximboldi/immer/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('de8411c84830864604bb685dc8f2e3c0dbdc40b95b2f6726092f7dcc85e75209')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  echo "Extracting ${_realname}-${pkgver}.tar.gz ..."
  tar -xzf ${_realname}-${pkgver}.tar.gz || true
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_extra_config[@]}" \
      -DDISABLE_WERROR=ON \
      -Dimmer_BUILD_TESTS=OFF \
      -Dimmer_BUILD_EXAMPLES=OFF \
      -Dimmer_BUILD_DOCS=OFF \
      -Dimmer_BUILD_EXTRAS=OFF \
      ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
